#pragma once

#include <d3d11.h>
#include <d3dcompiler.h>
#include <d3d10.h>
#include <DirectXMath.h>

#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3dcompiler.lib")

using namespace DirectX;

struct ConstantBuffer
{
	XMMATRIX World;
	XMMATRIX View;
	XMMATRIX Projection;
};


class cxc
{
public:
	void set()
	{
		world = XMMatrixIdentity();
		ConstantBuffer c;

		c.World = XMMatrixIdentity();
		c.World = XMMatrixTranspose(world);
	}
protected:
	XMMATRIX world;
	XMMATRIX view;
	XMMATRIX projection;
};


class XCxcD3D11Drawer
{
public:
	XCxcD3D11Drawer();
	~XCxcD3D11Drawer();
	void initializeScene();
	virtual void update();
	virtual void draw();
	void rotateX(float ang);
	void rotateY(float ang);
	void rotateZ(float ang);

protected:

	ConstantBuffer *cb;

	XMMATRIX *world;
	XMMATRIX *view;
	XMMATRIX *projection;

	ID3D11InputLayout *vertexLayout;

	ID3D11VertexShader *vertexShader;
	ID3D11PixelShader *pixelShader;
	ID3DBlob *vertexShaderBuffer;
	ID3DBlob *pixelShaderBuffer;

	ID3D11Buffer *constantBuffer;

	//XD3D11Ball *ball;
	//XD3D11Cube *cube;
	//XD3D11Anchor *anchor;

public:
	struct Vertex
	{
		void set(float x, float y, float z, float r, float g, float b, float a)
		{
			position = XMFLOAT3(x, y, z);
			color = XMFLOAT4(r, g, b, a);
		}

		XMFLOAT3 position;
		XMFLOAT4 color;
	};

	void setHWND(HWND hWnd);
	void setWidth(int width);
	void setHeight(int height);
	ID3D11Device *getDevice() const;
	ID3D11DeviceContext *getContext() const;
	bool initializeD3D11App();
//	virtual void initializeScene();
//	virtual void update();
//	virtual void draw();
	void XCreateSimpleBuffer(UINT bindFlags, const void * pSysMem, UINT byteWidth, ID3D11Buffer ** buffer);
	void XCreateSimpleBufferNull(UINT bindFlags, UINT byteWidth, ID3D11Buffer ** buffer);

protected:
	//	void XCreateSimpleLayout(LPCWSTR srcFile, LPCSTR functionName, ID3D10Blob * *shaderBuffer, );

	ID3D11Device *device;
	ID3D11DeviceContext *context;
	IDXGISwapChain *swapChain;
	ID3D11RenderTargetView *renderTargetView;
	HWND hWnd;
	int height;
	int width;
};

